#include <project.h>
/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module Debug.c - Functions which allow debug statements to be added to code |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Common/Debug.c $ 
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#define DEBUG_C

#include <stdio.h>
#include <string.h>
#include <aclstr.h>

#ifdef  DEBUG_ON_SDS

#include <stdarg.h>
/********************************************************************************************* 
* @func void | vdSDSDebug | 
*       SDS Debugger output function.
*       This function behaves like a printf to the SDS Debugger console window.
*       The data to be displayed must be terminated with a newline before it is displayed,
*       and so one is added to the end of the formatted data.
*       Also, the debugio_write command has a limit of 128 characters to display.
*        
* @parm const char *| chFormat
*       Foramt of the data to be displayed.
*
* @parm ... *| va_list arg
*       Parameter list used for the formatting.
*
* @end
**********************************************************************************************/
void vdSDSDebug(const char* chFormat,...) {
    char chString[128];
    va_list args;

    va_start(args, chFormat);
    memset(chString, '\0', strlen(chString));
    vsprintf(chString, chFormat, args);

    /* Add new line because the output is not displayed until a new line is sent */
    strcat(chString, "\n");    
    debugio_write(chString, strlen(chString));
    va_end(argptr);
}
#endif

#define DEBUG_95

#include <define.h>
#include <print.h>
#include <spdebug.h>

#ifdef DEBUG_ON_PRN

/*-----------------------------------------------------------------------------
* Routine Name  : pprintf
* Description   :
* Input         : char *, int, int, int
* Output        : FALSE
* Notes         : -> none
*
* Modification History:
*
*        #       Who                  Why and What
*       ---    ---------       --------------------------
*        1     Henry_G1        Created
*----------------------------------------------------------------------------*/

#include <printer.h>

int pprintf(char* pchFormat,...) {
    char pchFormatMessageBuf[250];

    va_list argp;
    char* tmp;

    pchFormatMessageBuf[0] = 0;

    if (pchFormat != 0) {
        tmp = strchr(pchFormat, '%');
        if (tmp) {
            va_start(argp, pchFormat);
            vsprintf(pchFormatMessageBuf, pchFormat, argp);
            va_end(argp);
        } else
            strcpy(pchFormatMessageBuf, pchFormat);
    }

    if (obPrinter.inType > 0 && obPrinter.inType <= 2) {
        shPrintFns[obPrinter.inType]((short) obPrinter.inHandle, (unsigned char *) pchFormatMessageBuf);
        shPrintFns[obPrinter.inType]((short) obPrinter.inHandle, (unsigned char *) "\n");
    }

    return(FALSE);
}

#endif /* DEBUG_ON_PRN */

#ifdef DEBUG_ON_PCOM

/*-----------------------------------------------------------------------------
* Routine Name  : cprintf
* Description   :
* Input         : char *, int, int, int
* Output        : FALSE
* Notes         : -> none
*
* Modification History:
*
*        #       Who                  Why and What
*       ---    ---------       --------------------------
*        1     Henry_G1        Created
*----------------------------------------------------------------------------*/

#include <printer.h>

int pprintf(char* pchFormat,...) {
    char pchFormatMessageBuf[250];

    va_list argp;
    char* tmp;

    pchFormatMessageBuf[0] = 0;

    if (pchFormat != 0) {
        tmp = strchr(pchFormat, '%');
        if (tmp) {
            va_start(argp, pchFormat);
            vsprintf(pchFormatMessageBuf, pchFormat, argp);
            va_end(argp);
        } else
            strcpy(pchFormatMessageBuf, pchFormat);
    }

    if (obPrinter.inType > 0 && obPrinter.inType <= 2) {
        shPrintFns[obPrinter.inType]((short) obPrinter.inHandle, (unsigned char *) pchFormatMessageBuf);
        shPrintFns[obPrinter.inType]((short) obPrinter.inHandle, (unsigned char *) "\n");
    }

    return(FALSE);
}

#endif /* DEBUG_ON_PCOM */

#ifdef DEBUG_ON_DSP

int dprintf(char* pchFormat,...) {
    char pchFormatMessageBuf[250];

    va_list argp;
    char* tmp;

    pchFormatMessageBuf[0] = 0;

    if (pchFormat != 0) {
        tmp = strchr(pchFormat, '%');
        if (tmp) {
            va_start(argp, pchFormat);
            vsprintf(pchFormatMessageBuf, pchFormat, argp);
            va_end(argp);
        } else
            strcpy(pchFormatMessageBuf, pchFormat);
    }

    clrscr();
    printf(pchFormatMessageBuf);
    get_char();
    return(VS_SUCCESS);
}

#endif // DEBUG_ON_DSP

#undef DEBUG_C

